;
$(document).ready(function() {
	//点击验证码
	mui('body').on("tap", ".yzm", function() {
		var phone = $("#phone").val();
		var code = $("#code").val();
		var password = $("#pass").val();
		var store=$("#store").val();
		var repass=$("#repass").val();
		$("#phone, #code, #pass, #store, #repass").blur();
		if(phone && password) {
			mui.confirm("将发送验证码至" + phone + "手机", " ", ["发送", "取消"], function(s) {
				if(s.index == 0) {
					require(weburl + model_sendY, "json", "post", {
						phone: phone
					}, function(e) {
						console.log(JSON.stringify(e));
						mui.alert(e.msg, " ", "确定", function() {}, "div");
					}, function() {
						mui.alert("发送验证码失败", " ", "确定", function() {}, "div");
					})
				}
			}, "div")
			return false;
		} else if(!phone) {
			console.log(phone)
			mui.alert("手机号码不能为空", " ", "确定", function() {}, "div");
			return false;
		}
		mui.alert("密码不能为空", " ", "确定", function() {}, "div");
	})

	//点击注册
	mui("body").on("tap", ".register", function() {
		var phone = $("#phone").val();
		var code = $("#code").val();
		var password = $("#pass").val();
		var store=$("#store").val();
		var repass=$("#repass").val();
		$("#phone, #code, #pass, #store, #repass").blur();
		if(phone && code && password&&store&&repass) {
			//请求注册接口
			require(weburl+model_register, "json", 'post', {
				name: store,
				phone: phone,
				password: password,
				password_confirmation: repass,
				verification_code: code
			}, function(response) {
				console.log(JSON.stringify(response));
				mui.alert(response.msg, " ", "确定", function() {
					if (response.status=="success") {
						mui.openWindow("../view/login.html","login");
					}
				}, "div");
			},function(){
				mui.alert("注册失败，请稍后再试", " ", "确定", function() {}, "div");
			})
			return false;
		} else if(!phone) {
			mui.alert("手机号码不能为空", " ", "确定", function() {}, "div");
			return false;
		} else if(!code) {
			mui.alert("验证码不能为空", " ", "确定", function() {}, "div");
			return false;
		}else if(!store){
			mui.alert("店铺名称不能为空", " ", "确定", function() {}, "div");
			return false;
		}else if(!repass){
			mui.alert("确认密码不能为空", " ", "确定", function() {}, "div");
			return false;
		}
		mui.alert("密码不能为空", " ", "确定", function() {}, "div");
	})
})